﻿Imports System.Data.OleDb

Public Class Add_New
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    End Sub

    Protected Sub btn_add_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btn_add.Click

        'Saving the photo the User uploads, with a random name, and after checking that there is actually a file

        Dim myGUID As New System.Guid
        myGUID = Guid.NewGuid()
        Dim newFileName = myGUID.ToString() + ".jpg"


        If (photo_upload.HasFile) Then
            photo_upload.SaveAs(Request.MapPath("Pictures") & "/" & newFileName)
        End If


        'Creation of a new database connection, command, and SQL String

        Dim oleDbConn As New OleDbConnection(ConfigurationManager.ConnectionStrings("ExperiencesConnectionString").ConnectionString)
        Dim sqlString As String
        sqlString = "INSERT INTO Experiences(exp_Author, exp_Title, exp_Location, exp_When, exp_Photo, exp_Description) VALUES (@f1, @f2, @f3, @f4, @f5, @f6)"

        Dim cmd As OleDbCommand
        cmd = New OleDbCommand(sqlString, oleDbConn)
        cmd.CommandType = CommandType.Text
        cmd.Parameters.AddWithValue("@f1", tb_name.Text)
        cmd.Parameters.AddWithValue("@f2", tb_title.Text)
        cmd.Parameters.AddWithValue("@f3", tb_location.Text)
        cmd.Parameters.AddWithValue("@f4", tb_when.Text)
        cmd.Parameters.AddWithValue("@f5", "Pictures/" & newFileName)
        cmd.Parameters.AddWithValue("@f6", tb_description.Text)

        oleDbConn.Open()
        cmd.ExecuteNonQuery()

        Response.Redirect("confirmation.aspx")








    End Sub
End Class